<template>
	<view class="containerbox">
		<uv-navbar title="通知公告" auto-back placeholder />
		
		<z-paging ref="paging" class="containerbox" v-model="list" @query="querylist">
			<template #loading>
				<dw_loading :status="loading" />
			</template>
			
			<view class="px-30">
				<uni-swipe-action>
					<uni-swipe-action-item  v-for="item, index in list" :key="index">
						<view class="w100 pt-10 flex-bottom" @tap.stop="goInfo(item.id)">
							<view class="text-20 mb-50 text-center color9 info-time"> {{ item.createTime }}</view>
							
							<view class="info-content">
								<view class="text-30 color-3a font-weight-600 u-line-2" style="position: relative" :style="item.isView.value==0 ? 'text-indent: 1em' : ''">
									<text class="dian w-15 h-15 bgc-red mr-5" v-if="item.isView.value==0" style="position: absolute;top: 10rpx" />
									{{ item.title }}
								</view>
								
								<view class="text-28 mt-15 color6">
									<mp-html :content="item.content" />
								</view>
							</view>
						</view>
						
						<template #right>
							<image :src="`${imgPath}mine/del-message.svg`" class="w-80 h-80 pt-90 my-auto ml-30" @tap.stop="deletsMessage(index, item.id)" />
						</template>
					</uni-swipe-action-item>
				</uni-swipe-action>
			</view>
		</z-paging>
	</view>
</template>

<script setup>
	
	import { imgPath } from '@/common/config.js'
	import { ref, nextTick } from 'vue'
	import { onShow } from "@dcloudio/uni-app"
	import { messageList, deleteMessages, viewMessage } from '@/common/apis/other'
	
	let paging = ref(null)
	let list = ref([])
	let loading = ref(true)
	
	async function querylist(page, pageSize) {//获取列表
		let params = { page, pageSize, simplePage: 1 }
		let result = await messageList(params)
		paging.value.complete(result)
		loading.value = false
	}
	
	function deletsMessage(index, id) {
		uni.$fui.modal({
			content: '请确认是否删除该消息？',
			success: async () => {
				await deleteMessages({ ids: [id] })
				if (list.value.length > 1) list.value.splice(index, 1)
				else list.value = []
				uni.$fui.toast('删除成功~')
			}
		})
	}
	
	async function goInfo(id) {
		await viewMessage({ id })
		uni.$fui.href('/pages/other/noticeInfo', { id })
	}
	
	onShow(() => {
		loading.value = true
		nextTick(paging.value?.reload)
	})
	
</script>

<style scoped lang="scss">
	::v-deep .uni-swipe_button-group view{ display: flex}
	.color-3a{color: #3A3F5E}
	.color6{color: #626780;line-height: 48rpx}
	.color9{color: #999999}
	.dian{display: block;border-radius: 50%}
	.info {
		margin-bottom: 20rpx;
		padding: 0 32rpx;
		&-time{margin: 28rpx auto; display: block; color: #8D8F9D}
		&-content{background-color: #FFFFFF; border-radius: 16rpx; padding: 40rpx}
	}
</style>